import router from "@/router";
import {getToken} from "@/utils/token.js"
import {LOGIN_PATH, REGISTER_PATH, FORGOT_PASSWORD_PATH, HOME_PATH} from "@/const/RouterPathConst";
const igroneUrl = [
    REGISTER_PATH,
    FORGOT_PASSWORD_PATH,
]

router.beforeEach((to, from, next) => {

    if (getToken()) {
        if (to.path === REGISTER_PATH) {
            next({path: HOME_PATH})
            return
        }
    }

    if (igroneUrl.includes(to.path)) {
        next();
        return;
    }
    if (getToken()) {
        if (to.path === LOGIN_PATH) {
            next({path: HOME_PATH})
            return
        }
    } else {
        if (to.path !== LOGIN_PATH) {
            next({path: LOGIN_PATH})
            return
        }
    }

    console.log(to, from)
    next()
})

router.afterEach((to, from) => {

})